package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PromotionChannel 小程序推广渠道
type PromotionChannel struct {
	ID          string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	Name        string `json:"name" gorm:"column:name;type:string;size:20;uniqueIndex:idx_name;comment:渠道名称"`
	TotalMember int64  `json:"total_member" gorm:"column:total_member;type:int;size:64;comment:总会员数"`
	TotalDevice int64  `json:"total_device" gorm:"column:total_device;type:int;size:64;comment:总设备"`
	CreatedAt   int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64"`
	UpdatedAt   int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64"`
}

func (PromotionChannel) TableName() string {
	return "promotion_channel"
}

// BeforeCreate 自增id
func (m *PromotionChannel) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PromotionChannel{})
}
